package org.footballmanager.pandafootball.system.controller;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.common.util.DateUtils;
import org.footballmanager.pandafootball.system.domain.FootSj;
import org.footballmanager.pandafootball.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
@RequestMapping("/task")
public class TaskController{
	@Autowired
	private FootSjService footSjService;
    @Autowired
    private FootMissionService footMissionService;
    @Autowired
    private FootMissionHistoryService footMissionHistoryService;
    @Autowired
    private FootUserService footUserService;
    @Autowired
    private FootCupbmService footCupbmService;

    @RequestMapping(value = "/search")
    public String search() {
        return "foot/task/List";
    }

    @RequestMapping(value="/processTask")
    @ResponseBody
	public String processMissionEveryDay(HttpServletRequest request, @RequestParam Integer type) {
        FootSj sj = footSjService.getRunningSj();
        Date date = new Date();
        switch (type){
            case 1:
                footMissionService.addNewMission(sj.getSjzt(), request);
                break;
            case 2:
                footMissionHistoryService.processHistoryRecord();
                break;
            case 3:
                footSjService.processFirstDay(sj);
                break;
            case 4:
                footSjService.process21Day(sj);
                break;
            case 5:
                //结束八分之一决赛,开始四分之一决赛
                footCupbmService.endCupGames(2, request);
                break;
            case 6:
                //结束四分之一决赛,开始半决赛
                footCupbmService.endCupGames(3, request);
                break;
            case 7:
                //结束半决赛,开始决赛
                footCupbmService.endCupGames(4, request);
                break;
            case 8:
                int day = DateUtils.getNowDay(date);
                int endDay = DateUtils.getMonthEnd(date);
                footSjService.process28Day(date, day, endDay);
                break;
            case 9:
                footSjService.processLastDay(date);
                break;
            case 10:
                footUserService.processUserNoLogin();
                break;
            default:
                break;
        }
		return Constants.OK;
	}
}
